package com.my.admin.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.my.admin.entity.Image;
import com.my.admin.service.ImageService;
import com.my.admin.util.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "图片接口", tags = "图片接口")
@RestController
@RequestMapping("api")
@CrossOrigin
public class ImageApiController {

    @Autowired
    private ImageService service;

    @ApiOperation("随机返回一条数据")
    @GetMapping("image/rand")
    public Rest randOne() {
        return Rest.ok().setData("image", service.randOne());
    }

    @ApiOperation("根据页码页数及条件查询图片")
    @PostMapping("image/get")
    public Rest users(@RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize, @RequestBody Image image) {
        return Rest.ok().setData("page", service.pageList(new Page<>(pageNo, pageSize), image));
    }

}
